﻿using System.Collections.Generic;
using System.Threading.Tasks;

namespace SimulationCenter.Tasks.Svrs
{
    /// <summary>
    /// 任务服务
    /// </summary>
    public interface ITaskSvr
    {
        /// <summary>
        /// 获取所有需要恢复的任务
        /// </summary>
        /// <returns></returns>
        Task<List<ScTask>> GetRecoveryTasks();

        /// <summary>
        /// 获取主任务
        /// </summary>
        /// <param name="id">主任务编号</param>
        /// <returns></returns>
        Task<ScTask> GetTask(int id);

        /// <summary>
        /// 尝试获取设备的下一个任务
        /// </summary>
        /// <param name="scTaskId">主任务编号</param>
        /// <param name="device">设备任务</param>
        /// <returns></returns>
        Task<ScDeviceTask> TryGetNextDeviceTask(int scTaskId, string device);

        /// <summary>
        /// 查看主任务是否存在除指定设备外其他的子任务
        /// </summary>
        /// <param name="scTaskId"></param>
        /// <param name="device"></param>
        /// <returns></returns>
        Task<bool> ExistsOtherDeviceTask(int scTaskId, string device);

        /// <summary>
        /// 创建设备任务
        /// </summary>
        /// <param name="scTaskId">主任务编号</param>
        /// <param name="device">设备号</param>
        /// <param name="subscription">公众号</param>
        /// <returns></returns>
        Task BindDeviceTask(int scTaskId, string device, string subscription);

        /// <summary>
        /// 更新任务
        /// </summary>
        /// <param name="scTask"></param>
        /// <returns></returns>
        Task UpdateTask(ScTask scTask);

        /// <summary>
        /// 更新设备任务
        /// </summary>
        /// <param name="scDeviceTask"></param>
        /// <returns></returns>
        Task UpdateDeviceTask(ScDeviceTask scDeviceTask);

        /// <summary>
        /// 根据公众号获取设备任务
        /// </summary>
        /// <param name="subscription"></param>
        /// <returns></returns>
        List<ScDeviceTask> GetDeviceTasksBySubscription(string subscription);

        /// <summary>
        /// 创建主任务
        /// </summary>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="subscriptionRange"></param>
        /// <param name="targetDevices"></param>
        /// <param name="status"></param>
        /// <param name="targetSubscriptions"></param>
        /// <param name="msgRange"></param>
        /// <param name="lastDays"></param>
        /// <param name="loopMode"></param>
        /// <param name="cron"></param>
        /// <returns></returns>
        Task<ScTask> CreateTask(string name, string description, ScSubscriptionRange subscriptionRange,
            string targetDevices, ScTaskStatus status = ScTaskStatus.Ready, string targetSubscriptions = null,
            ScMsgRange msgRange = ScMsgRange.All, int? lastDays = null, ScLoopMode loopMode = ScLoopMode.Once,
            string cron = null);

        /// <summary>
        /// 添加初始化任务
        /// </summary>
        /// <param name="deviceSerials"></param>
        /// <returns></returns>
        Task AddStartUpTasks(List<string> deviceSerials);

        /// <summary>
        /// 获取正在运行的初始化任务
        /// </summary>
        /// <returns></returns>
        Task<ScTask> GetRunningStartUpTask();
    }
}
